from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-04 14:07:18.624294
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 04, Mar, 2021
Time: 14:07:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.5578
Nobs: 220.000 HQIC: -47.3855
Log likelihood: 2554.57 FPE: 1.50494e-21
AIC: -47.9461 Det(Omega_mle): 1.00873e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.464816 0.134951 3.444 0.001
L1.Burgenland 0.065891 0.068735 0.959 0.338
L1.Kärnten -0.211297 0.058706 -3.599 0.000
L1.Niederösterreich 0.167206 0.156137 1.071 0.284
L1.Oberösterreich 0.240281 0.139722 1.720 0.085
L1.Salzburg 0.212271 0.074077 2.866 0.004
L1.Steiermark 0.107496 0.100000 1.075 0.282
L1.Tirol 0.124705 0.067138 1.857 0.063
L1.Vorarlberg -0.010382 0.061194 -0.170 0.865
L1.Wien -0.146187 0.130234 -1.122 0.262
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.478295 0.161509 2.961 0.003
L1.Burgenland 0.011575 0.082262 0.141 0.888
L1.Kärnten 0.349480 0.070259 4.974 0.000
L1.Niederösterreich 0.088828 0.186864 0.475 0.635
L1.Oberösterreich -0.111807 0.167218 -0.669 0.504
L1.Salzburg 0.197926 0.088655 2.233 0.026
L1.Steiermark 0.196073 0.119679 1.638 0.101
L1.Tirol 0.142670 0.080350 1.776 0.076
L1.Vorarlberg 0.155822 0.073236 2.128 0.033
L1.Wien -0.495646 0.155863 -3.180 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.311128 0.062634 4.967 0.000
L1.Burgenland 0.094436 0.031902 2.960 0.003
L1.Kärnten -0.020158 0.027247 -0.740 0.459
L1.Niederösterreich 0.079630 0.072467 1.099 0.272
L1.Oberösterreich 0.302733 0.064848 4.668 0.000
L1.Salzburg 0.011226 0.034381 0.327 0.744
L1.Steiermark -0.008415 0.046412 -0.181 0.856
L1.Tirol 0.072844 0.031160 2.338 0.019
L1.Vorarlberg 0.098711 0.028401 3.476 0.001
L1.Wien 0.064706 0.060444 1.071 0.284
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222597 0.067670 3.289 0.001
L1.Burgenland 0.001003 0.034467 0.029 0.977
L1.Kärnten 0.018816 0.029438 0.639 0.523
L1.Niederösterreich 0.039696 0.078294 0.507 0.612
L1.Oberösterreich 0.386505 0.070062 5.517 0.000
L1.Salzburg 0.085055 0.037145 2.290 0.022
L1.Steiermark 0.175949 0.050144 3.509 0.000
L1.Tirol 0.043598 0.033666 1.295 0.195
L1.Vorarlberg 0.083752 0.030685 2.729 0.006
L1.Wien -0.057734 0.065305 -0.884 0.377
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.514009 0.134249 3.829 0.000
L1.Burgenland 0.068363 0.068377 1.000 0.317
L1.Kärnten 0.013620 0.058401 0.233 0.816
L1.Niederösterreich -0.008412 0.155324 -0.054 0.957
L1.Oberösterreich 0.128413 0.138994 0.924 0.356
L1.Salzburg 0.061578 0.073691 0.836 0.403
L1.Steiermark 0.106055 0.099479 1.066 0.286
L1.Tirol 0.218423 0.066788 3.270 0.001
L1.Vorarlberg 0.027429 0.060875 0.451 0.652
L1.Wien -0.119013 0.129556 -0.919 0.358
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192137 0.097548 1.970 0.049
L1.Burgenland -0.021633 0.049684 -0.435 0.663
L1.Kärnten -0.009934 0.042435 -0.234 0.815
L1.Niederösterreich 0.043965 0.112861 0.390 0.697
L1.Oberösterreich 0.416067 0.100996 4.120 0.000
L1.Salzburg -0.006948 0.053545 -0.130 0.897
L1.Steiermark -0.017823 0.072283 -0.247 0.805
L1.Tirol 0.175932 0.048529 3.625 0.000
L1.Vorarlberg 0.042893 0.044233 0.970 0.332
L1.Wien 0.192158 0.094138 2.041 0.041
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.238354 0.125421 1.900 0.057
L1.Burgenland 0.031837 0.063881 0.498 0.618
L1.Kärnten -0.038353 0.054560 -0.703 0.482
L1.Niederösterreich -0.040274 0.145110 -0.278 0.781
L1.Oberösterreich -0.070223 0.129854 -0.541 0.589
L1.Salzburg 0.069118 0.068846 1.004 0.315
L1.Steiermark 0.401581 0.092937 4.321 0.000
L1.Tirol 0.453385 0.062396 7.266 0.000
L1.Vorarlberg 0.156739 0.056872 2.756 0.006
L1.Wien -0.199402 0.121036 -1.647 0.099
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126320 0.149329 0.846 0.398
L1.Burgenland 0.021743 0.076058 0.286 0.775
L1.Kärnten -0.071720 0.064961 -1.104 0.270
L1.Niederösterreich 0.187469 0.172772 1.085 0.278
L1.Oberösterreich -0.012400 0.154607 -0.080 0.936
L1.Salzburg 0.255619 0.081969 3.118 0.002
L1.Steiermark 0.141443 0.110653 1.278 0.201
L1.Tirol 0.048978 0.074290 0.659 0.510
L1.Vorarlberg 0.063935 0.067713 0.944 0.345
L1.Wien 0.242012 0.144109 1.679 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.573699 0.080191 7.154 0.000
L1.Burgenland -0.035779 0.040844 -0.876 0.381
L1.Kärnten -0.016020 0.034885 -0.459 0.646
L1.Niederösterreich -0.001201 0.092780 -0.013 0.990
L1.Oberösterreich 0.307087 0.083026 3.699 0.000
L1.Salzburg 0.018284 0.044018 0.415 0.678
L1.Steiermark -0.006845 0.059422 -0.115 0.908
L1.Tirol 0.078203 0.039895 1.960 0.050
L1.Vorarlberg 0.120654 0.036363 3.318 0.001
L1.Wien -0.030744 0.077388 -0.397 0.691
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.130815 0.039057 0.188014 0.242122 0.056307 0.131278 -0.039944 0.166500
Kärnten 0.130815 1.000000 0.003759 0.196771 0.164748 -0.113772 0.148442 0.012001 0.316257
Niederösterreich 0.039057 0.003759 1.000000 0.272745 0.063372 0.248454 0.169491 0.050421 0.348122
Oberösterreich 0.188014 0.196771 0.272745 1.000000 0.296231 0.277987 0.094373 0.075245 0.133066
Salzburg 0.242122 0.164748 0.063372 0.296231 1.000000 0.128313 0.044693 0.085935 -0.003798
Steiermark 0.056307 -0.113772 0.248454 0.277987 0.128313 1.000000 0.128167 0.120577 -0.106744
Tirol 0.131278 0.148442 0.169491 0.094373 0.044693 0.128167 1.000000 0.180610 0.160673
Vorarlberg -0.039944 0.012001 0.050421 0.075245 0.085935 0.120577 0.180610 1.000000 0.026433
Wien 0.166500 0.316257 0.348122 0.133066 -0.003798 -0.106744 0.160673 0.026433 1.000000